package com.vue3.blog.web;

import com.vue3.blog.common.resp.PageVO;
import com.vue3.blog.common.resp.Result;
import com.vue3.blog.domain.dto.CommentDTO;
import com.vue3.blog.domain.vo.CommentListVO;
import com.vue3.blog.domain.vo.CommentTreeVO;
import com.vue3.blog.service.ICommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Mr.小朱同学
 * @version 1.0.0
 * @date 2025/6/13 19:44
 * @description 文章评论
 */
@RestController
@RequestMapping("/api/comment")
public class CommentController {
    @Resource
    private ICommentService commentService;

    @PostMapping("/save")
    public Result<Void> save(@RequestBody @Valid CommentDTO dto) {
        commentService.saveComment(dto);
        return Result.success("评论成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<Void> remove(@PathVariable Long id) {
        commentService.removeComment(id);
        return Result.success("删除评论");
    }

    @GetMapping("/frontend/list")
    public Result<List<CommentTreeVO>> getFrontendCommentList(@RequestParam Long postId) {
        return Result.success("前台-评论列表", commentService.getFrontendCommentList(postId));
    }

    @GetMapping("/list")
    public Result<PageVO<CommentListVO>> getCommentList() {
        return Result.success("评论列表", commentService.getCommentList());
    }

}